package com.chookss.tools;

import android.content.Context;
import android.view.Gravity;

import com.hjq.toast.IToastStyle;
import com.hjq.toast.ToastUtils;
import com.chookss.MyApp;

/**
 * TODO: 2018/11/2 解决重复toast问题
 */
public class MyToast {

    public static void show(String msg) {
        try {
//            ToastUtils.initStyle(new DefaultToastStyle());
            ToastUtils.show(msg);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public static void t(Context context, String string) {
        try {
            if (context == null) {
                return;
            }
//            ToastUtils.initStyle(new DefaultToastStyle());
            ToastUtils.show(string);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public static void t(String msg) {
//        ToastUtils.initStyle(new DefaultToastStyle());
        ToastUtils.show(msg);
    }
    public  static void center(String msg){
        try {
            ToastUtils.initStyle(new CenterToastStyle());
            ToastUtils.show(msg);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    private static class CenterToastStyle implements IToastStyle {

        @Override
        public int getGravity() {
            return Gravity.CENTER;
        }

        @Override
        public int getXOffset() {
            return 0;
        }

        @Override
        public int getYOffset() {
            int offSetY = Utils.dip2px(MyApp.appCtx,64);
            if (offSetY < 100) offSetY = 128;
            return offSetY;
        }

        @Override
        public int getZ() {
            return 3;
        }

        @Override
        public int getCornerRadius() {
            return 2;
        }

        @Override
        public int getBackgroundColor() {
            return 0Xe0333333;
        }

        @Override
        public int getTextColor() {
            return 0XFFFFFFFF;
        }

        @Override
        public float getTextSize() {
            return 15;
        }

        @Override
        public int getMaxLines() {
            return 2;
        }

        @Override
        public int getPaddingStart() {
            return 15;
        }


        @Override
        public int getPaddingTop() {
            return 7;
        }

        @Override
        public int getPaddingEnd() {
            return 15;
        }

        @Override
        public int getPaddingBottom() {
            return 7;
        }
    }
    private static class DefaultToastStyle implements IToastStyle {

        @Override
        public int getGravity() {
            return Gravity.BOTTOM;
        }

        @Override
        public int getXOffset() {
            return 0;
        }

        @Override
        public int getYOffset() {
            int offSetY = Utils.dip2px(MyApp.appCtx,64);
            if (offSetY < 100) offSetY = 128;
            return offSetY;
        }

        @Override
        public int getZ() {
            return 3;
        }

        @Override
        public int getCornerRadius() {
            return 2;
        }

        @Override
        public int getBackgroundColor() {
            return 0Xe0333333;
        }

        @Override
        public int getTextColor() {
            return 0XFFFFFFFF;
        }

        @Override
        public float getTextSize() {
            return 15;
        }

        @Override
        public int getMaxLines() {
            return 2;
        }

        @Override
        public int getPaddingStart() {
            return 15;
        }

        @Override
        public int getPaddingTop() {
            return 7;
        }

        @Override
        public int getPaddingEnd() {
            return 15;
        }

        @Override
        public int getPaddingBottom() {
            return 7;
        }
    }
}
